<?php
class Comment_model extends CI_Model{

	function _construct(){
		parent::_construct();
	}
	
	function create_comment($comment, $ref_id, $ref_type ,$created_by_id, $created_date,$attachment){
		$data = array(
			'comment'		=> $comment,
			'ref_id'		=> $ref_id,
			'ref_type'		=> $ref_type,
			'created_by_id'	=> $created_by_id,
		   	'created_date' 	=> $created_date,
			'attachment'    => $attachment
		);
		
		$this->db->insert('comments', $data);
		return $this->db->insert_id();
	}
	
	function delete_task_comment($id){
		$this->db->delete('comments', array('comment_id' => $id)); 
	}
	
	function get_task_comments($task_id){
		$this->db->select('comments.comment_id,
					comments.comment, 
					comments.created_date,
					comments.attachment,
					users.firstname,
					users.lastname');
		
		$this->db->from('comments','users');
		$this->db->join('users', 'comments.created_by_id = users.id', 'left');
		$this->db->where('comments.ref_type', 'task');
		$this->db->where('comments.ref_id', $task_id);
		 		
		$query = $this->db->get();
		return $query->result_array();
	}
}
?>